package com.example.login;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LoginController {

    @GetMapping("/login")
    public String login() {
        return "login"; // 返回登录页面
    }

    @PostMapping("/login")
    public String login(@RequestParam String username, @RequestParam String password, Model model) {
        if ("admin".equals(username) && "admin".equals(password)) {
            model.addAttribute("message", "欢迎光临");
            return "welcome"; // 登录成功，返回欢迎页面
        }
        model.addAttribute("error", "用户名或密码错误");
        return "login"; // 登录失败，返回登录页面
    }
} 